// reference: http://blog.csdn.net/bill200711022/article/details/8309858
function split(array, low, high) {
    var i = low;
    var x = array[low];
    var temp;
    for(var j = low + 1; j <= high; j++) {
        if(array[j] <= x) {
            i ++;
            if(i != j) {
                temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
        }
    }
 
    temp = array[low];
    array[low] = array[i];
    array[i] = temp;
    return [array, i];
}
 
function select(array, low, high, k) {
    if(low === high) {
        return low;
    } else {
        var result = split(array, low, high);
        array = result[0];
        var mid = result[1];
        if(mid - low + 1 >= k) {
            return select(array, low, mid, k);
        } else {
            return select(array, mid+1, high, k - (mid-low+1));
        }
    }
}
 
console.log(select([4,0,7,2,8,1,9,4,3], 0, 5, 3));